From 18c11e5e35b3edd6172f659caca43d2dcfdc401e Mon Sep 17 00:00:00 2001 From: robertl Date: Sun, 6 Mar 2011 20:42:53 +0000 Subject: [PATCH] Add device transparency for Magellan Explorist x10 models. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4051 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/explorist_ini.c | 45 ++++++++++++++++++++++++++++++++++++++++ gpsbabel/explorist_ini.h | 12 +++++++++++ gpsbabel/magproto.c | 27 +++++++++++++++++++++++- 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 gpsbabel/explorist_ini.c create mode 100644 gpsbabel/explorist_ini.h diff --git a/gpsbabel/explorist_ini.c b/gpsbabel/explorist_ini.c new file mode 100644 index 000000000..cc6136e54 --- /dev/null +++ b/gpsbabel/explorist_ini.c @@ -0,0 +1,45 @@ +#include "defs.h" +#include "inifile.h" +#include "explorist_ini.h" + +static inifile_t *inifile; +static const char myname[] = "explorist"; + +const char * +explorist_read_value(const char* section, const char *key) { + return inifile_readstr(inifile, section, key); +} + +mag_info * +explorist_ini_get() { + mag_info *info = xmalloc(sizeof(mag_info)); + char *s; + + inifile = inifile_init("Geocaches.ini", myname); + s = xstrdup(inifile_readstr(inifile, "Geocaches", "GeocachesPath")); + s = gstrsub(s, "\\", "/"); + info->geo_path = s; + inifile_done(inifile); + + inifile = inifile_init("Tracks.ini", myname); + s = xstrdup(inifile_readstr(inifile, "Tracks", "TracksExportPath")); + s = gstrsub(s, "\\", "/"); + info->track_path = xstrappend(s, "/tracks.gpx");; + inifile_done(inifile); + + inifile = inifile_init("Waypoints.ini", myname); + s = xstrdup(inifile_readstr(inifile, "Waypoints", "WaypointsPath")); + s = gstrsub(s, "\\", "/"); + info->waypoint_path = xstrappend(s, "/newwaypoints.gpx"); + inifile_done(inifile); + + return info; +} + +void +explorist_ini_done(mag_info *info) { + xfree(info->geo_path); + xfree(info->track_path); + xfree(info->waypoint_path); + xfree(info); +} diff --git a/gpsbabel/explorist_ini.h b/gpsbabel/explorist_ini.h new file mode 100644 index 000000000..fce970806 --- /dev/null +++ b/gpsbabel/explorist_ini.h @@ -0,0 +1,12 @@ + +/* + * Interesting traits of the device from the *.ini files. + */ +typedef struct { + char* geo_path; + char* track_path; + char* waypoint_path; +} mag_info; + +mag_info * explorist_ini_get(); +void explorist_ini_done(mag_info *info); diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index 96aba229f..5d89110de 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -1,7 +1,8 @@ /* Communicate Thales/Magellan serial protocol. - Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Robert Lipe, robertlipe@usa.net + Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, + 2008, 2010 Robert Lipe, robertlipe@usa.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,6 +26,7 @@ #include "defs.h" #include "magellan.h" #include "gbser.h" +#include "explorist_ini.h" static int bitrate = 4800; static int wptcmtcnt; @@ -52,6 +54,10 @@ static int waypoint_read_count; static int wpt_len = 8; static const char *curfname; static int extension_hint; +// For Explorist GC/510/610/710 familes, bludgeon in GPX support. +// (This has nothing to do with the Explorist 100...600 products.) +static ff_vecs_t *gpx_vec; +static mag_info *explorist_info; /* * Magellan's firmware is *horribly* slow to send the next packet after @@ -741,6 +747,15 @@ mag_rd_init_common(const char *portname) { char *ext; waypoint_read_count = 0; + // For Explorist GC, intercept the device access and redirect to GPX. + // We actually do the rd_init() inside read as we may have multiple + // files that we have to read. + if (0 == strcmp(portname, "usb:")) { + char *vec_opts = NULL; + explorist_info = explorist_ini_get(); + gpx_vec = find_vec("gpx", &vec_opts); + return; + } if (bs) { bitrate=atoi(bs); @@ -855,6 +870,10 @@ mag_wr_init(const char *portname) static void mag_deinit(void) { + if (explorist_info) { + explorist_ini_done(explorist_info); + return; + } mag_handoff(); termdeinit(); if(mkshort_handle) @@ -1191,6 +1210,12 @@ mag_wptparse(char *trkmsg) static void mag_read(void) { + if (gpx_vec) { + gpx_vec->rd_init(explorist_info->track_path); + gpx_vec->read(); + return; + } + found_done = 0; if (global_opts.masked_objective & TRKDATAMASK) { magrxstate = mrs_handoff; -- 2.30.2